package com.data4.supplier.controller;


import com.data4.feignapi.common.constants.GatewayConstants;
import com.data4.feignapi.dto.PhonePwdLoginDTO;
import com.data4.feignapi.dto.Result;
import com.data4.feignapi.dto.SupplierDTO;
import com.data4.supplier.service.ProductService;
import com.data4.supplier.service.SupplierService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Forever
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/supplier")
@Tag(name = "供应商管理")
public class SupplierController {

    @Resource
    private SupplierService supplierService;
    @Resource
    private ProductService productService;

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result register(@RequestBody SupplierDTO supplierDTO) {
        return supplierService.register(supplierDTO);
    }

    @Operation(summary = "供应商登录")
    @PostMapping("/login")
    public Result login(@RequestBody PhonePwdLoginDTO pwdLoginDTO) {
        return supplierService.login(pwdLoginDTO);
    }

    @Operation(summary = "查询供应商列表")
    @PostMapping("/getSupplier/{current}/{num}")
    public Result getSupplier(@PathVariable Integer current, @PathVariable Integer num) {
        return supplierService.getSupplier(current, num);
    }
    @GetMapping("/getProductsSupplier/{current}/{num}")
    @Operation(summary = "根据时间和供应商查询商品")
    public Result getProduct(@PathVariable Long current, @PathVariable Long num,
                             @RequestHeader(GatewayConstants.X_SUPPLIER_ID) String supplierId) {
        return productService.getProductSupplier(current, num,supplierId);
    }
    @GetMapping("/getSupplierById")
    @Operation(summary = "根据供应商id查询供应商")
    public Result getSupplierById(@RequestHeader(GatewayConstants.X_SUPPLIER_ID) String supplierId) {
        return Result.ok(supplierService.getSupplierById(Integer.parseInt(supplierId)));
    }
    @GetMapping("/getProductByNameLike/{current}/{num}")
    @Operation(summary = "根据商品名称模糊查询商品")
    public Result getProductByNameLike(@RequestParam("productName") String productName,
                                       @PathVariable Integer current,
                                       @PathVariable Integer num,
                                       @RequestHeader(GatewayConstants.X_SUPPLIER_ID) String supplierId) {
        return Result.ok(productService.getProductByNameLike(productName, current,
                num, Integer.parseInt(supplierId)));
    }

    @GetMapping("/getProductByMarkerPriceScope/{current}/{num}")
    @Operation(summary = "根据市场价格区间查询商品")
    public Result getProductByMarkerPriceScope(@PathVariable("current") Integer current,
                                               @PathVariable("num") Integer num,
                                               @RequestParam(required = false) Integer little,
                                               @RequestParam(required = false) Integer big,
                                               @RequestHeader(GatewayConstants.X_SUPPLIER_ID)
                                                   String supplierId) {
        return productService.getProductByMarkerPriceScope(current, num, little, big,
                Integer.parseInt(supplierId));
    }
    //前端写枚举
    @PostMapping("/getProductGroup")
    @Operation(summary = "根据商品分组查询商品的价格信息")
    public Result getProductGroup(@RequestBody List<String> group,
                                  @RequestHeader(GatewayConstants.X_SUPPLIER_ID)
                                  String supplierId) {
        return productService.getProductGroup(group, Integer.parseInt(supplierId));
    }
}

